package com.redis.base.interceptor;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;

import com.redis.base.annotation.Lock;
import com.redis.base.redis.RedisTools;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ReflectionUtils;

/**
 * 缓存拦截
 */

public class CacheInterceptor  {

	private static final Logger logger = LoggerFactory.getLogger(CacheInterceptor.class);
	
	public Object intercept(MethodInvocation invo) throws Throwable {
		try {
			Method[] methods = ReflectionUtils.getAllDeclaredMethods(invo.getThis().getClass());
			if (methods == null || methods.length <=0) {
				return invo.proceed();
			}
			for (Method method : methods) {
				if(method.getName().equals(invo.getMethod().getName())) {
					Annotation  lock = AnnotationUtils.findAnnotation(method,Lock.class);
					//Object result = invo.proceed();
				}
			}
		}catch(Exception e) {
			logger.error(e.getMessage());
		}
		return invo.proceed();
	}

 
}